package com.itqf.service.impl;


import com.itqf.bean.DtsOrderExample;
import com.itqf.mapper.DtsOrderMapper;
import com.itqf.service.DtsOrderService;
import com.itqf.vo.CategorySellAmts;
import com.itqf.vo.CategorySellVo;
import com.itqf.vo.DayStatis;
import com.itqf.vo.OrderAmtsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * projectName: gp_manage
 *
 * @author: 赵伟风
 * time: 2021/8/18 17:54
 * description:
 */
@Service
public class DtsOrderServiceImpl implements DtsOrderService {


    @Autowired
    private DtsOrderMapper dtsOrderMapper;

    /**
     * 查询全部订单数量
     *
     * @return
     */
    @Override
    public Long findOrderTotal() {

        DtsOrderExample example = new DtsOrderExample();

        DtsOrderExample.Criteria criteria = example.createCriteria();

        criteria.andDeletedEqualTo(false);

        Long orderTotal = dtsOrderMapper.countByExample(example);

        return orderTotal;
    }

    /**
     * 查询品牌关联订单
     *
     * @param brandIds
     * @return
     */
    @Override
    public Long findOrderTotal(List<Integer> brandIds) {

       Long orderTotal = dtsOrderMapper.selectTotalByBrandIds(brandIds);

        return orderTotal;
    }


    /**
     * 类别的销售额
     *
     * @return
     */
    @Override
    public CategorySellVo findOrderCategorySell() {

        //1.查询原始数据

        List<CategorySellAmts> amtsList =  dtsOrderMapper.selectSell();

        //2.封装数据
        String [] categoryNames = new String[amtsList.size()];

        int index = 0;
        for (CategorySellAmts sellAmts : amtsList) {
            categoryNames[index] = sellAmts.getName();
            index++;
        }

        CategorySellVo categorySellVo = new CategorySellVo();
        categorySellVo.setCategoryNames(categoryNames);
        categorySellVo.setCategorySellData(amtsList);

        return categorySellVo;
    }



    /**
     * 订单 30天内的销售额
     *
     * @return
     */
    @Override
    public OrderAmtsVo findOrderSell() {

        //1.查询原始数据
        List<DayStatis> dayStatis = dtsOrderMapper.selectDaySell();

        //2.封装数据
        //日期数据
        String[] dayData = new String[dayStatis.size()];
        //日订单金额
        BigDecimal[] orderAmtData = new BigDecimal[dayStatis.size()];
        //日订单量
        int [] orderCntData = new int[dayStatis.size()];

        for (int i = 0; i < dayStatis.size(); i++) {
            dayData[i] = dayStatis.get(i).getDayStr();
            orderAmtData[i]= dayStatis.get(i).getAmts();
            orderCntData[i]= dayStatis.get(i).getCnts();
        }

        OrderAmtsVo orderAmtsVo = new OrderAmtsVo();

        orderAmtsVo.setDayData(dayData);
        orderAmtsVo.setOrderAmtData(orderAmtData);
        orderAmtsVo.setOrderCntData(orderCntData);

        return orderAmtsVo;
    }
}
